/**
 * 
 */
package co.fitstart.entity.order;

import com.demo2do.core.utils.Alias;

/**
 * 
 * @author mohanlan
 *
 */
@Alias("paymentMethod")
public enum PaymentMethod {

    /** 支付宝 */
    ALIPAY("alipay", "支付宝（口碑）", "支付宝（口碑）", "3"),
    
    /** 微信 */
    WECHAT("wechat", "微信", "财付通", "4"),
    
    /** 淘宝 */
    TAOBAO("taobao", "淘宝", "淘宝", "6"),
    
    /** paypal */
    PAYPAL("paypal", "Paypal", "PAYPAL", "5"),
    
    /** 京东 */
    JD("jd", "京东", "京东", "7"),
    
    /** 现金 */
    CASH("cash", "现金", "现金", "1"),
    
    POS("pos", "移动POS", "银行", "8"),
    
    /** 其他 */
    OTHER("other", "其他", "其他", "9"),
    
    /** 体验券 */
    COUPON("coupon", "体验券", "财付通", "4"),
    
    PUDONG_DEVELOPMENT("pudong_development", "浦发银行", "浦发银行", "201"),
    
    CONSTRUCTION_BANK("construction_bank", "建设银行", "建设银行", "202"),
    
    MERCHANTS_BANK("merchants_bank", "招商银行", "招商银行", "203"),
    
    CHINA_BANK("china_bank", "中国银行", "中国银行", "204"),
    
    ZHESHANG_BANK("zheshang_bank", "浙商银行", "浙商银行", "205");
    
    private String alias;
    
    private String description;
    
    private String name;
    
    private String code;
    
    PaymentMethod(String alias, String description, String name, String code) {
        this.alias = alias;
        this.description = description;
        this.name = name;
        this.code = code;
    }
    
    public boolean isNotWechat() {
        return !this.equals(PaymentMethod.WECHAT);
    }
    
    /**
     * @return the alias
     */
    public String getAlias() {
        return alias;
    }
    
    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }
    
    /**
     * 
     * @return the name
     */
    public String getName() {
        return name;
    }
    
    /**
     * 
     * @return the code
     */
    public String getCode() {
        return code;
    }
    
    /**
     * Get payment method according to alias
     * 
     * @param alias
     * @return
     */
    public static PaymentMethod aliasOf(String alias) {
        for (PaymentMethod paymentMethod : PaymentMethod.values()) {
            if (paymentMethod.getAlias().equalsIgnoreCase(alias)) {
                return paymentMethod;
            }
        }
        return null;
    }
    
    /**
     * 
     * @param code
     * @return
     */
    public static PaymentMethod codeOf(String code) {
        for (PaymentMethod paymentMethod : PaymentMethod.values()) {
            if (code != null && code.startsWith(paymentMethod.toString())) {
                return paymentMethod;
            }
        }
        return null;
    }
    
    /**
     * 
     * @param code
     * @return
     */
    public static String getDescriptionByCode(String code) {
        for (PaymentMethod paymentMethod : PaymentMethod.values()) {
            if (paymentMethod.getCode().equals(code)) {
                return paymentMethod.getDescription();
            }
        }
        return null;
    }
}
